<?php
global_config::get_instance()->add_server_class("ArrayOfSoapCharacteristic","soap_array_of_characteristic");
require_once(dirname(__FILE__)."/soap_array_base.class.php");
class soap_array_of_characteristic extends soap_array_base
{	
	/**
	 * SoapCharacteristic
	 *
	 * @var soap_characteristic
	 */
	public $SoapCharacteristic = array();

	public  function add($item)
	{
		parent::add($this->SoapCharacteristic, $item);
	}

	public function load_from_db($chain_id) {
		$dba = db_adapter::get_instance();


		$characteristic_composition = new  characteristic_characteristic_type_composition();
		$criteria = new query_criteria();
		$criteria->add_criterion_composite($characteristic_composition->chain_characteristic,$characteristic_composition->chain_characteristic->chain_id,criterion_type::$equal,$chain_id);

		$characteristic_composition_list = $dba->get_composite_list($characteristic_composition,$criteria);

		while ($characteristic = $characteristic_composition_list->get_next(false, true))
		{
			$temp  = new soap_characteristic();
			$temp->Both = $characteristic->chain_characteristic->both_value->get_value();
			$temp->End = $characteristic->chain_characteristic->end_value->get_value();
			$temp->Start = $characteristic->chain_characteristic->start_value->get_value();
			$temp->Type = $characteristic->chain_characteristic_type->chain_characteristic_type_name->get_value();
			$this->add($temp);
		}
	}

	public function as_array()
	{
		return parent::to_array($this->SoapCharacteristic);
	}
	
	public function save_to_db($parent_id)
	{
	      foreach($this->as_array() as $element){
            $temp = $element;
            $temp->chain_id = $parent_id;
            $temp->save_to_db();
        }
	}
}
?>